import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';

export namespace DressResourceApi {
  /** 移动端主题配置 */
  export interface MobileThemeConfig {
    type?: 'chinese' | 'european' | 'modern' | 'vintage' | 'bohemian' | 'custom';
    primaryColor?: string;
    secondaryColor?: string;
    backgroundImage?: string;
    fontFamily?: string;
    headerStyle?: 'classic' | 'elegant' | 'simple';
    cardStyle?: 'shadow' | 'border' | 'gradient';
    customCss?: string;
  }

  /** 婚纱资源信息 */
  export interface DressResource {
    id: number;
    dressCode?: string;
    dressName?: string;
    style: string;
    size: string;
    color: string;
    brand: string;
    rentalPrice: number;
    inventoryCount: number;
    status: string;
    images?: string[];
    mobileThemeConfig?: MobileThemeConfig;
  }

  /** 婚纱租赁订单 */
  export interface DressRentalOrder {
    id: number;
    orderId: string;
    dressCode: string;
    customerId: string;
    customerName: string;
    rentStartDate: string;
    rentEndDate: string;
    rentDays: number;
    totalAmount: number;
    paidAmount: number;
    depositAmount: number;
    status: string;
    createTime: string;
  }
}

const resourceBaseUrl = '/wedding/resource/dress';
// ==================== 标准CRUD接口 (/wedding/dress-resource) ====================

/** 查询婚纱资源分页 */
export function getDressResourcePage(params: PageParam) {
  return requestClient.get<PageResult<DressResourceApi.DressResource>>(resourceBaseUrl+'/page', { params });
}

/** 查询婚纱资源详情 */
export function getDressResource(id: number) {
  return requestClient.get<DressResourceApi.DressResource>(resourceBaseUrl+`/get?id=${id}`);
}

/** 新增婚纱资源 */
export function createDressResource(data: DressResourceApi.DressResource) {
  return requestClient.post(resourceBaseUrl+'/create', data);
}

/** 修改婚纱资源 */
export function updateDressResource(data: DressResourceApi.DressResource) {
  return requestClient.put(resourceBaseUrl+'/update', data);
}

/** 删除婚纱资源 */
export function deleteDressResource(id: number) {
  return requestClient.delete(resourceBaseUrl+ `/delete?id=${id}`);
}

/** 导出婚纱资源 */
export function exportDressResource(params: any) {
  return requestClient.download(resourceBaseUrl+'/export-excel', { params });
}

// ==================== 扩展功能接口 (/wedding/resource/dress) ====================


/** 获取婚纱租赁订单 */
export function getDressRentalOrders(dressCode: string) {
  return requestClient.get<DressResourceApi.DressRentalOrder[]>(
    `${resourceBaseUrl}/rental-orders`,
    { params: { dressCode } },
  );
}

/** 获取库存历史 */
export function getInventoryHistory(dressCode: string) {
  return requestClient.get<any[]>(`${resourceBaseUrl}/inventory-history`, {
    params: { dressCode },
  });
}

/** 更新库存 */
export function updateInventory(dressCode: string, quantity: number) {
  return requestClient.put(`${resourceBaseUrl}/update-inventory`, {
    dressCode,
    quantity,
  });
}

/** 获取可用婚纱列表 */
export function getAvailableDresses(params: {
  startDate: string;
  days: number;
  category?: string;
}) {
  return requestClient.get<DressResourceApi.DressResource[]>(
    `${resourceBaseUrl}/available`,
    { params },
  );
}

/** 上传婚纱图片 */
export function uploadDressImage(file: File) {
  const formData = new FormData();
  formData.append('file', file);
  return requestClient.post<string>(`${resourceBaseUrl}/upload-image`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}

/** 通过分享码获取婚纱信息 */
export function getDressByShareCode(shareCode: string) {
  return requestClient.get<DressResourceApi.DressResource>(`${resourceBaseUrl}/share/${shareCode}`);
}


